Imports MIMS.WRS.Entities
Imports MIMS.WRS.Business
Imports System.Text
Imports System.IO
Imports MyFramework

Public Class BODetail
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents ddlType As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents txtProductCode As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtColor As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDescription As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtQtyOrdered As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtQtyCompleted As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtQtyAbove50 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtQtyBelow50 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtStkLastCheck As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtFOB As System.Web.UI.WebControls.TextBox
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.ValidationSummary
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RangeValidator1 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator2 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator3 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator4 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator5 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator6 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents btnSave As System.Web.UI.WebControls.Button
    Protected WithEvents ddlOwner As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtCatalogue As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPage As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlPack As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtPackQty As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlCat As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtSalesDescription2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtSalesDescription1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkTarget As System.Web.UI.WebControls.CheckBox
    Protected WithEvents ddlStockLocated As System.Web.UI.WebControls.DropDownList
    Protected WithEvents chkNotAvailInUSA As System.Web.UI.WebControls.CheckBox
    Protected WithEvents btnFakeSubmit As System.Web.UI.HtmlControls.HtmlInputButton
    Protected WithEvents hidCurrentOwner As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents txtBONo As System.Web.UI.WebControls.TextBox
    Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
    Protected WithEvents txtQtyShipped As System.Web.UI.WebControls.TextBox
    Protected WithEvents Rangevalidator7 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents txtQtyNotShipped As System.Web.UI.WebControls.TextBox
    Protected WithEvents Rangevalidator8 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents txtMinOrderQty As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtTallPalletQty As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlIDSSort As System.Web.UI.WebControls.DropDownList
    Protected WithEvents chkArchived As System.Web.UI.WebControls.CheckBox
    Protected WithEvents ddlCatPackDesc As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtMUKTHGCatPackQty As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlMUKTHGCatPackDesc As System.Web.UI.WebControls.DropDownList    
    Protected WithEvents Rangevalidator10 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents chkIsShownInLGDCatalog As System.Web.UI.WebControls.CheckBox
    Protected WithEvents rdbIsShownYes As System.Web.UI.WebControls.RadioButton
    Protected WithEvents rdbIsShownNo As System.Web.UI.WebControls.RadioButton
    Protected WithEvents txtSpecOfferDisc As System.Web.UI.WebControls.TextBox
    Protected WithEvents CompareFieldValidator1 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents txtQtyUnitsPer40Cont As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtQtyUnitsPer20Cont As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtUnitWeight As System.Web.UI.WebControls.TextBox
    Protected WithEvents hidTerritoryID As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents hidProductCode As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents ddlHCCCode As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Rangevalidator99 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RangeValidator9 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents chkProductRound As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtheightS1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS4 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS5 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth4 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth5 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS6 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS7 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtheightS8 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth6 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth7 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWidth8 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS4 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS5 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS6 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS7 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenOrLenS8 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS4 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS5 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS6 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS7 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDiaOrLenS8 As System.Web.UI.WebControls.TextBox
    Protected WithEvents lnkViewProductPicture As System.Web.UI.WebControls.LinkButton
    Protected WithEvents spanShowPicture As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents hidProductCodeForViewPicture As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents ddlUnits As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtMinQtyVolume As System.Web.UI.WebControls.TextBox
    Protected WithEvents hidUnitValueArray As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents txtMinOrderDesc As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtUnitsPerOuter As System.Web.UI.WebControls.TextBox
    Protected WithEvents Comparevalidator1 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents txtUnitFOBPrice As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents calCompletedDate As DateTimePicker
    Protected WithEvents calEstimatedDate As DateTimePicker
    Protected WithEvents calOrderDate As DateTimePicker
    Protected WithEvents calStartDate As DateTimePicker
    Protected WithEvents calStkLastCheckDate As DateTimePicker

    Private boo As BulkOrder = Nothing
    Private pd As ProductDimensions = Nothing

    Protected ReadOnly Property IsAddNew() As Boolean
        Get
            If RequestContext.BulkOrderID <= 0 Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property

    Protected Function GetDOListUrl() As String
        Return ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, RequestContext.BulkOrderID, RequestContext.ChainOfID, False, RequestContext.Changed, 1))
    End Function

    'Private Sub BuildNavigator()
    '    Dim sb As StringBuilder = New StringBuilder

    '    If RequestContext.ChainOfID.Length > 0 Then
    '        Dim i As Int32
    '        ' RequestContext.SelectedIDs.Count always >= 2
    '        For i = 0 To RequestContext.SelectedIDs.Count - 2
    '            Dim id As String = Convert.ToString(RequestContext.SelectedIDs(i))

    '            If (id.Equals(RequestContext.BulkOrderID.ToString())) Then
    '                sb.AppendFormat("<span class=""Selected"">[{0}]</span>", id)
    '            Else
    '                sb.AppendFormat("<a href=""{0}"">[{1}]</a>", _
    '                    ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, Integer.Parse(id), RequestContext.ChainOfID, False, RequestContext.Changed, 0)), id)
    '            End If

    '            sb.Append("&nbsp;&nbsp;")
    '        Next
    '    Else
    '        sb.Append("<span class=""Selected"">[NEW RECORD]</span>")
    '    End If

    '    'ltrNavigator.Text = sb.ToString()
    'End Sub

    Private Function BuildObject() As Boolean
        If IsAddNew Then
            boo = New BulkOrder
            pd = New ProductDimensions
            'set default value
            boo.SpecialOfferDisc = 0
        Else
            Try
                boo = BulkOrderService.GetBulkOrder(RequestContext.BulkOrderID)
                pd = BulkOrderService.GetProductDimensions(RequestContext.BulkOrderID)
                If boo Is Nothing Then
                    Throw New Exception
                End If
                If pd Is Nothing Then
                    pd = New ProductDimensions
                End If
            Catch ex As Exception
                Me.lblMessage.Text = "Failed to load bulk order. Object not found or has been deleted"
                Return False
            End Try
        End If
        Return True
    End Function

    Private Sub UpdateData(ByVal bSave As Boolean)
        If (bSave) Then
            boo.Color = txtColor.Text
            boo.CompletedDate = calCompletedDate.SelectedValue
            boo.Description = txtDescription.Text

            Try
                If txtFOB.Text.Trim().Length > 0 Then boo.FOB = Decimal.Parse(txtFOB.Text)
            Catch ex As Exception
            End Try
            Try
                If txtUnitsPerOuter.Text.Trim().Length > 0 Then boo.UnitsPerOuter = Convert.ToInt32(txtUnitsPerOuter.Text)
            Catch ex As Exception
            End Try
            Try
                boo.UnitFOBPrice = Decimal.Parse((boo.FOB / boo.UnitsPerOuter).ToString(Config.DecimalFormat))
            Catch ex As Exception
                If txtUnitFOBPrice.Text.Trim().Length > 0 Then boo.UnitFOBPrice = Decimal.Parse(txtUnitFOBPrice.Text)
            End Try
            boo.OrderDate = calOrderDate.SelectedValue
            boo.ProductCode = txtProductCode.Text
            ProductCode = boo.ProductCode
            boo.StartDate = calStartDate.SelectedValue
            boo.StockLastCheckedDate = calStkLastCheckDate.SelectedValue
            Try
                If txtStkLastCheck.Text.Trim().Length > 0 Then boo.StockLastCheckedQty = Integer.Parse(txtStkLastCheck.Text)
            Catch ex As Exception
            End Try

            boo.Type = Byte.Parse(ddlType.SelectedItem.Value)
            boo.SupplierCode = RequestContext.SupplierCode
            boo.Owner = Integer.Parse(ddlOwner.SelectedItem.Value)

            If (boo.Type <> EBOType.Ordered) Then 'if stock, set null                
                'For "Type" = Stock, the Available Quantity should go into
                'Total Quantity Completed field. If it goes in the Completed field 
                'then it will go in the Qty available field automatically
                Try
                    If txtQtyOrdered.Text.Trim().Length > 0 Then boo.TotalQtyCompleted = Integer.Parse(txtQtyOrdered.Text)
                Catch ex As Exception
                End Try
                'boo.TotalQtyCompleted = Nulls.NullInteger
                boo.TotalQtyInProgressAbove50P = Nulls.NullInteger
                boo.TotalQtyInProgressBelow50P = Nulls.NullInteger
                boo.EstimatedDate = Nulls.NullDate
            Else

                Try
                    If txtQtyOrdered.Text.Trim().Length > 0 Then boo.TotalQtyOrdered = Integer.Parse(txtQtyOrdered.Text)
                Catch ex As Exception
                End Try

                Try
                    If txtQtyCompleted.Text.Trim().Length > 0 Then
                        boo.TotalQtyCompleted = Integer.Parse(txtQtyCompleted.Text)
                    Else
                        boo.TotalQtyCompleted = 0 'Nulls.NullInteger
                    End If
                Catch ex As Exception
                End Try
                Try
                    If txtQtyAbove50.Text.Trim().Length > 0 Then
                        boo.TotalQtyInProgressAbove50P = Integer.Parse(txtQtyAbove50.Text)
                    Else
                        boo.TotalQtyInProgressAbove50P = Nulls.NullInteger
                    End If
                Catch ex As Exception
                End Try
                Try
                    If txtQtyBelow50.Text.Trim().Length > 0 Then
                        boo.TotalQtyInProgressBelow50P = Integer.Parse(txtQtyBelow50.Text)
                    Else
                        boo.TotalQtyInProgressBelow50P = Nulls.NullInteger
                    End If
                Catch ex As Exception
                End Try

                boo.EstimatedDate = calEstimatedDate.SelectedValue
            End If

            boo.Catalogue = txtCatalogue.Text.Trim()
            boo.Page = txtPage.Text
            boo.Pack = ddlPack.SelectedItem.Value
            Try
                If txtPackQty.Text.Trim().Length > 0 Then boo.PackQty = Integer.Parse(txtPackQty.Text)
            Catch ex As Exception
            End Try
            boo.CatPackDesc = ddlCatPackDesc.SelectedItem.Value

            boo.CatalogID = Integer.Parse(ddlCat.SelectedItem.Value)
            boo.SalesDescription1 = txtSalesDescription1.Text.Trim()
            boo.SalesDescription2 = txtSalesDescription2.Text.Trim()

            boo.Target = chkTarget.Checked
            boo.StockLocation = ddlStockLocated.SelectedItem.Value
            boo.AvailableInUSA = Not chkNotAvailInUSA.Checked
            boo.BONo = txtBONo.Text

            If txtMinOrderQty.Text.Trim().Length > 0 Then
                Try
                    boo.MinOrderQtyValue = Integer.Parse(txtMinOrderQty.Text)
                Catch ex As Exception
                End Try
            Else
                boo.MinOrderQtyValue = Nulls.NullInteger
            End If

            boo.MinOrderQty = txtMinOrderDesc.Text
            'Try
            '    If txtMinOrderQty.Text.Trim().Length > 0 Then
            '        boo.MinOrderQty = Integer.Parse(txtMinOrderQty.Text)
            '    Else
            '        boo.MinOrderQty = Nulls.NullInteger
            '    End If

            'Catch ex As Exception
            'End Try

            If txtMinQtyVolume.Text.Trim().Length > 0 Then
                boo.MinQtyVolume = Decimal.Parse(txtMinQtyVolume.Text.Replace(",", ""))
            Else
                boo.MinQtyVolume = Nulls.NullDecimal
            End If
            boo.TallPaletQty = txtTallPalletQty.Text
            boo.UnitSettingID = Convert.ToInt32(ddlUnits.SelectedValue)

            boo.IDSSortID = Convert.ToInt32(ddlIDSSort.SelectedItem.Value)
            boo.IsArchived = chkArchived.Checked
            boo.MUKTHGCatPackDesc = ddlMUKTHGCatPackDesc.SelectedItem.Value
            Try
                If txtMUKTHGCatPackQty.Text.Trim().Length > 0 Then
                    boo.MUKTHGCatPackQty = Integer.Parse(txtMUKTHGCatPackQty.Text)
                Else
                    boo.MUKTHGCatPackQty = 1
                End If
            Catch ex As Exception
                boo.MUKTHGCatPackQty = 1
            End Try
            'Try
            '    If txtHomeDelivered15Price.Text.Trim().Length > 0 Then boo.HomeDelivered15Price = Decimal.Parse(txtHomeDelivered15Price.Text)
            'Catch ex As Exception
            'End Try
            'boo.CurrencyID = Convert.ToInt32(ddlCurrency.SelectedItem.Value)

            boo.IsShownInLGDCatalog = rdbIsShownYes.Checked

            If (boo.IsShownInLGDCatalog = False) Then
                boo.PackQty = 1
            End If

            Try
                If txtSpecOfferDisc.Text.Trim().Length > 0 Then
                    boo.SpecialOfferDisc = Decimal.Parse(txtSpecOfferDisc.Text)
                Else
                    boo.SpecialOfferDisc = Nulls.NullDecimal
                End If

                With boo
                    If txtQtyUnitsPer40Cont.Text.Trim().Length > 0 Then
                        .QtyUnitsPer40Cont = Integer.Parse(txtQtyUnitsPer40Cont.Text.Replace(",", ""))
                    Else
                        .QtyUnitsPer40Cont = Nulls.NullInteger
                    End If
                    If txtQtyUnitsPer20Cont.Text.Trim().Length > 0 Then
                        .QtyUnitsPer20Cont = Integer.Parse(txtQtyUnitsPer20Cont.Text.Replace(",", ""))
                    Else
                        .QtyUnitsPer20Cont = Nulls.NullInteger
                    End If
                    If txtUnitWeight.Text.Trim().Length > 0 Then
                        .UnitWeight = Decimal.Parse(txtUnitWeight.Text.Replace(",", ""))
                    Else
                        .UnitWeight = Nulls.NullDecimal
                    End If

                    .HCC_Code = ddlHCCCode.SelectedValue

                End With

            Catch ex As Exception
            End Try
            boo.ModifiedDate = DateTime.Now
        Else
        txtColor.Text = boo.Color
        If boo.CompletedDate <> Nulls.NullDate Then calCompletedDate.SelectedValue = boo.CompletedDate
        txtDescription.Text = boo.Description
        If boo.EstimatedDate <> Nulls.NullDate Then calEstimatedDate.SelectedValue = boo.EstimatedDate
            If boo.FOB <> Nulls.NullDecimal Then txtFOB.Text = boo.FOB.ToString(Config.DecimalFormat)
            If (boo.UnitsPerOuter <> Nulls.NullInteger AndAlso boo.UnitsPerOuter <> 0) Then txtUnitsPerOuter.Text = boo.UnitsPerOuter.ToString()
            If boo.UnitFOBPrice <> Nulls.NullDecimal Then txtUnitFOBPrice.Text = boo.UnitFOBPrice.ToString(Config.DecimalFormat)

            calOrderDate.SelectedValue = boo.OrderDate
            txtProductCode.Text = boo.ProductCode
            ProductCode = boo.ProductCode
            BulkOrderID = boo.BulkOrderID
            If boo.StartDate <> Nulls.NullDate Then calStartDate.SelectedValue = boo.StartDate
            If boo.StockLastCheckedDate <> Nulls.NullDate Then calStkLastCheckDate.SelectedValue = boo.StockLastCheckedDate
            If boo.StockLastCheckedQty <> Nulls.NullInteger Then txtStkLastCheck.Text = boo.StockLastCheckedQty.ToString()
            If (boo.Type = EBOType.Ordered) Then
                If boo.TotalQtyCompleted <> Nulls.NullInteger Then txtQtyCompleted.Text = boo.TotalQtyCompleted.ToString()
                txtQtyOrdered.Text = boo.TotalQtyOrdered.ToString()
            Else
                If boo.TotalQtyCompleted <> Nulls.NullInteger Then txtQtyOrdered.Text = boo.TotalQtyCompleted.ToString()
            End If
            If boo.TotalQtyInProgressAbove50P <> Nulls.NullInteger Then txtQtyAbove50.Text = boo.TotalQtyInProgressAbove50P.ToString()
            If boo.TotalQtyInProgressBelow50P <> Nulls.NullInteger Then txtQtyBelow50.Text = boo.TotalQtyInProgressBelow50P.ToString()

            ddlType.SelectedIndex = ddlType.Items.IndexOf(ddlType.Items.FindByValue(boo.Type.ToString()))
            ddlOwner.SelectedIndex = ddlOwner.Items.IndexOf(ddlOwner.Items.FindByValue(boo.Owner.ToString()))
            'txtCatalogue.Text = boo.Catalogue
            txtPage.Text = boo.Page
            ddlPack.SelectedIndex = ddlPack.Items.IndexOf(ddlPack.Items.FindByValue(boo.Pack))
            If boo.PackQty <> Nulls.NullInteger Then txtPackQty.Text = boo.PackQty.ToString()
            ddlCatPackDesc.SelectedIndex = ddlCatPackDesc.Items.IndexOf(ddlCatPackDesc.Items.FindByValue(boo.CatPackDesc))

            Try
                ddlCat.SelectedIndex = ddlCat.Items.IndexOf(ddlCat.Items.FindByValue(boo.CatalogID.ToString))
            Catch ex As Exception

            End Try

            txtSalesDescription1.Text = boo.SalesDescription1
            txtSalesDescription2.Text = boo.SalesDescription2
            chkTarget.Checked = boo.Target

            Try
                ddlStockLocated.SelectedIndex = ddlStockLocated.Items.IndexOf(ddlStockLocated.Items.FindByValue(boo.StockLocation))
            Catch ex As Exception

            End Try

            Try
                ddlIDSSort.SelectedIndex = ddlIDSSort.Items.IndexOf(ddlIDSSort.Items.FindByValue(boo.IDSSortID.ToString()))
            Catch ex As Exception

            End Try


            chkNotAvailInUSA.Checked = Not boo.AvailableInUSA
            txtBONo.Text = boo.BONo

            'If boo.MinOrderQty <> Nulls.NullInteger Then txtMinOrderQty.Text = boo.MinOrderQty.ToString()
            If (boo.MinOrderQtyValue <> Nulls.NullInteger) AndAlso (boo.MinOrderQtyValue <> 0D) Then
                txtMinOrderQty.Text = boo.MinOrderQtyValue.ToString()
            Else
                txtMinOrderQty.Text = ""
            End If
            txtMinOrderDesc.Text = boo.MinOrderQty

            If (boo.MinQtyVolume <> Nulls.NullDecimal) AndAlso (boo.MinQtyVolume <> 0D) Then
                txtMinQtyVolume.Text = boo.MinQtyVolume.ToString(Config.DecimalFormat4)
            Else
                txtMinQtyVolume.Text = ""
            End If
            txtTallPalletQty.Text = boo.TallPaletQty
            Try
                If (boo.UnitSettingID <> Nulls.NullInteger) Then
                    ddlUnits.SelectedIndex = ddlUnits.Items.IndexOf(ddlUnits.Items.FindByValue(boo.UnitSettingID.ToString()))
                    'TODO: txtUnitValue.Text = UnitSettingService.GetUnitSetting(boo.UnitCode).CbmValue.ToString(Config.DecimalFormat4)
                End If
            Catch ex As Exception
            End Try

            chkArchived.Checked = boo.IsArchived

            If boo.MUKTHGCatPackQty <> Nulls.NullInteger Then txtMUKTHGCatPackQty.Text = boo.MUKTHGCatPackQty.ToString()
            ddlMUKTHGCatPackDesc.SelectedIndex = ddlMUKTHGCatPackDesc.Items.IndexOf(ddlMUKTHGCatPackDesc.Items.FindByValue(boo.MUKTHGCatPackDesc))
            'If boo.HomeDelivered15Price <> Nulls.NullDecimal Then txtHomeDelivered15Price.Text = boo.HomeDelivered15Price.ToString(Config.DecimalFormat)
            'ddlCurrency.SelectedIndex = ddlCurrency.Items.IndexOf(ddlCurrency.Items.FindByValue(boo.CurrencyID.ToString()))

            rdbIsShownYes.Checked = boo.IsShownInLGDCatalog
            rdbIsShownNo.Checked = Not rdbIsShownYes.Checked

            With boo
                If .SpecialOfferDisc <> Nulls.NullDecimal Then txtSpecOfferDisc.Text = .SpecialOfferDisc.ToString(Config.DecimalFormat)
                If .QtyUnitsPer40Cont <> Nulls.NullInteger Then txtQtyUnitsPer40Cont.Text = .QtyUnitsPer40Cont.ToString(Config.NumericFormat)
                If .QtyUnitsPer20Cont <> Nulls.NullInteger Then txtQtyUnitsPer20Cont.Text = .QtyUnitsPer20Cont.ToString(Config.NumericFormat)
                If .UnitWeight <> Nulls.NullDecimal Then txtUnitWeight.Text = .UnitWeight.ToString(Config.DecimalFormatEx)

                Dim hccCode As HarmonizedCommodityCodeCollection = HarmonizedCommodityCodeService.GetHarmonizedCommodityCodes()
                ddlHCCCode.DataSource = hccCode
                ddlHCCCode.DataTextField = HarmonizedCommodityCodeColumns.Description.ToString()
                ddlHCCCode.DataValueField = HarmonizedCommodityCodeColumns.HCCCode.ToString()
                ddlHCCCode.DataBind()
                ddlHCCCode.Items.Insert(0, New ListItem("---", String.Empty))
                Try
                    If .HCC_Code <> String.Empty Then ddlHCCCode.SelectedValue = .HCC_Code
                Catch ex As Exception

                End Try

            End With
            hidTerritoryID.Value = boo.TerritoryID.ToString
            hidProductCode.Value = boo.ProductCode
            End If

            UpdateProductDimensions(bSave, pd)
    End Sub

    Private Sub UpdateProductDimensions(ByVal bSave As Boolean, ByVal pd As ProductDimensions)
        If (bSave) Then
            pd.IsProductRound = chkProductRound.Checked
            With pd
                'Diameter/Lenght
                If txtDiaOrLenS1.Text.Trim().Length > 0 Then
                    .DiaOrLenS1 = Decimal.Parse(txtDiaOrLenS1.Text.Replace(",", ""))
                Else
                    .DiaOrLenS1 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS2.Text.Trim().Length > 0 Then
                    .DiaOrLenS2 = Decimal.Parse(txtDiaOrLenS2.Text.Replace(",", ""))
                Else
                    .DiaOrLenS2 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS3.Text.Trim().Length > 0 Then
                    .DiaOrLenS3 = Decimal.Parse(txtDiaOrLenS3.Text.Replace(",", ""))
                Else
                    .DiaOrLenS3 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS4.Text.Trim().Length > 0 Then
                    .DiaOrLenS4 = Decimal.Parse(txtDiaOrLenS4.Text.Replace(",", ""))
                Else
                    .DiaOrLenS4 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS5.Text.Trim().Length > 0 Then
                    .DiaOrLenS5 = Decimal.Parse(txtDiaOrLenS5.Text.Replace(",", ""))
                Else
                    .DiaOrLenS5 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS6.Text.Trim().Length > 0 Then
                    .DiaOrLenS6 = Decimal.Parse(txtDiaOrLenS6.Text.Replace(",", ""))
                Else
                    .DiaOrLenS6 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS7.Text.Trim().Length > 0 Then
                    .DiaOrLenS7 = Decimal.Parse(txtDiaOrLenS7.Text.Replace(",", ""))
                Else
                    .DiaOrLenS7 = Nulls.NullDecimal
                End If
                If txtDiaOrLenS8.Text.Trim().Length > 0 Then
                    .DiaOrLenS8 = Decimal.Parse(txtDiaOrLenS8.Text.Replace(",", ""))
                Else
                    .DiaOrLenS8 = Nulls.NullDecimal
                End If

                'Height
                If txtheightS1.Text.Trim().Length > 0 Then
                    .HeightS1 = Decimal.Parse(txtheightS1.Text.Replace(",", ""))
                Else
                    .HeightS1 = Nulls.NullDecimal
                End If
                If txtheightS2.Text.Trim().Length > 0 Then
                    .HeightS2 = Decimal.Parse(txtheightS2.Text.Replace(",", ""))
                Else
                    .HeightS2 = Nulls.NullDecimal
                End If
                If txtheightS3.Text.Trim().Length > 0 Then
                    .HeightS3 = Decimal.Parse(txtheightS3.Text.Replace(",", ""))
                Else
                    .HeightS3 = Nulls.NullDecimal
                End If
                If txtheightS4.Text.Trim().Length > 0 Then
                    .HeightS4 = Decimal.Parse(txtheightS4.Text.Replace(",", ""))
                Else
                    .HeightS4 = Nulls.NullDecimal
                End If
                If txtheightS5.Text.Trim().Length > 0 Then
                    .HeightS5 = Decimal.Parse(txtheightS5.Text.Replace(",", ""))
                Else
                    .HeightS5 = Nulls.NullDecimal
                End If
                If txtheightS6.Text.Trim().Length > 0 Then
                    .HeightS6 = Decimal.Parse(txtheightS6.Text.Replace(",", ""))
                Else
                    .HeightS6 = Nulls.NullDecimal
                End If
                If txtheightS7.Text.Trim().Length > 0 Then
                    .HeightS7 = Decimal.Parse(txtheightS7.Text.Replace(",", ""))
                Else
                    .HeightS7 = Nulls.NullDecimal
                End If
                If txtheightS8.Text.Trim().Length > 0 Then
                    .HeightS8 = Decimal.Parse(txtheightS8.Text.Replace(",", ""))
                Else
                    .HeightS8 = Nulls.NullDecimal
                End If

                If (chkProductRound.Checked = True) Then
                    'Width
                    .WidthS1 = Nulls.NullDecimal

                    .WidthS2 = Nulls.NullDecimal

                    .WidthS3 = Nulls.NullDecimal

                    .WidthS4 = Nulls.NullDecimal

                    .WidthS5 = Nulls.NullDecimal

                    .WidthS6 = Nulls.NullDecimal

                    .WidthS7 = Nulls.NullDecimal

                    .WidthS8 = Nulls.NullDecimal
                Else
                    'Width
                    If txtWidth1.Text.Trim().Length > 0 Then
                        .WidthS1 = Decimal.Parse(txtWidth1.Text.Replace(",", ""))
                    Else
                        .WidthS1 = Nulls.NullDecimal
                    End If
                    If txtWidth2.Text.Trim().Length > 0 Then
                        .WidthS2 = Decimal.Parse(txtWidth2.Text.Replace(",", ""))
                    Else
                        .WidthS2 = Nulls.NullDecimal
                    End If
                    If txtWidth3.Text.Trim().Length > 0 Then
                        .WidthS3 = Decimal.Parse(txtWidth3.Text.Replace(",", ""))
                    Else
                        .WidthS3 = Nulls.NullDecimal
                    End If
                    If txtWidth4.Text.Trim().Length > 0 Then
                        .WidthS4 = Decimal.Parse(txtWidth4.Text.Replace(",", ""))
                    Else
                        .WidthS4 = Nulls.NullDecimal
                    End If
                    If txtWidth5.Text.Trim().Length > 0 Then
                        .WidthS5 = Decimal.Parse(txtWidth5.Text.Replace(",", ""))
                    Else
                        .WidthS5 = Nulls.NullDecimal
                    End If
                    If txtWidth6.Text.Trim().Length > 0 Then
                        .WidthS6 = Decimal.Parse(txtWidth6.Text.Replace(",", ""))
                    Else
                        .WidthS6 = Nulls.NullDecimal
                    End If
                    If txtWidth7.Text.Trim().Length > 0 Then
                        .WidthS7 = Decimal.Parse(txtWidth7.Text.Replace(",", ""))
                    Else
                        .WidthS7 = Nulls.NullDecimal
                    End If
                    If txtWidth8.Text.Trim().Length > 0 Then
                        .WidthS8 = Decimal.Parse(txtWidth8.Text.Replace(",", ""))
                    Else
                        .WidthS8 = Nulls.NullDecimal
                    End If
                End If

            End With
        Else
            With pd
                chkProductRound.Checked = .IsProductRound

                If .DiaOrLenS1 <> Nulls.NullDecimal Then txtDiaOrLenS1.Text = .DiaOrLenS1.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS2 <> Nulls.NullDecimal Then txtDiaOrLenS2.Text = .DiaOrLenS2.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS3 <> Nulls.NullDecimal Then txtDiaOrLenS3.Text = .DiaOrLenS3.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS4 <> Nulls.NullDecimal Then txtDiaOrLenS4.Text = .DiaOrLenS4.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS5 <> Nulls.NullDecimal Then txtDiaOrLenS5.Text = .DiaOrLenS5.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS6 <> Nulls.NullDecimal Then txtDiaOrLenS6.Text = .DiaOrLenS6.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS7 <> Nulls.NullDecimal Then txtDiaOrLenS7.Text = .DiaOrLenS7.ToString(Config.DecimalFormatEx)
                If .DiaOrLenS8 <> Nulls.NullDecimal Then txtDiaOrLenS8.Text = .DiaOrLenS8.ToString(Config.DecimalFormatEx)

                If .HeightS1 <> Nulls.NullDecimal Then txtheightS1.Text = .HeightS1.ToString(Config.DecimalFormatEx)
                If .HeightS2 <> Nulls.NullDecimal Then txtheightS2.Text = .HeightS2.ToString(Config.DecimalFormatEx)
                If .HeightS3 <> Nulls.NullDecimal Then txtheightS3.Text = .HeightS3.ToString(Config.DecimalFormatEx)
                If .HeightS4 <> Nulls.NullDecimal Then txtheightS4.Text = .HeightS4.ToString(Config.DecimalFormatEx)
                If .HeightS5 <> Nulls.NullDecimal Then txtheightS5.Text = .HeightS5.ToString(Config.DecimalFormatEx)
                If .HeightS6 <> Nulls.NullDecimal Then txtheightS6.Text = .HeightS6.ToString(Config.DecimalFormatEx)
                If .HeightS7 <> Nulls.NullDecimal Then txtheightS7.Text = .HeightS7.ToString(Config.DecimalFormatEx)
                If .HeightS8 <> Nulls.NullDecimal Then txtheightS8.Text = .HeightS8.ToString(Config.DecimalFormatEx)

                If (Not .IsProductRound) Then
                    If .WidthS1 <> Nulls.NullDecimal Then txtWidth1.Text = .WidthS1.ToString(Config.DecimalFormatEx)
                    If .WidthS2 <> Nulls.NullDecimal Then txtWidth2.Text = .WidthS2.ToString(Config.DecimalFormatEx)
                    If .WidthS3 <> Nulls.NullDecimal Then txtWidth3.Text = .WidthS3.ToString(Config.DecimalFormatEx)
                    If .WidthS4 <> Nulls.NullDecimal Then txtWidth4.Text = .WidthS4.ToString(Config.DecimalFormatEx)
                    If .WidthS5 <> Nulls.NullDecimal Then txtWidth5.Text = .WidthS5.ToString(Config.DecimalFormatEx)
                    If .WidthS6 <> Nulls.NullDecimal Then txtWidth6.Text = .WidthS6.ToString(Config.DecimalFormatEx)
                    If .WidthS7 <> Nulls.NullDecimal Then txtWidth7.Text = .WidthS7.ToString(Config.DecimalFormatEx)
                    If .WidthS8 <> Nulls.NullDecimal Then txtWidth8.Text = .WidthS8.ToString(Config.DecimalFormatEx)
                End If

            End With
        End If
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Me.btnSubmit.Attributes("onclick") = "if (checkLogic()==false) return;"
        Security.DenyIDSUser()

        If Not IsPostBack Then
            'Put value of Unit into hiden field. Using it at client side
            Try
                Dim unitValueList As UnitSettingCollection = UnitSettingService.GetUnitSettingsOnly()
                Dim unitValueListByConPoint As UnitSettingCollection = UnitSettingService.GetUnitSettingsOnlyByConPoint(RequestContext.ConPointIDForBODetailSS)
                Dim conPointObj As ConPoint = ConPointService.GetConPoint(RequestContext.ConPointIDForBODetailSS)

                Dim values As String = ""
                Dim existed As Boolean = False
                Dim done As Boolean = False
                For Each item As UnitSetting In unitValueList
                    existed = False
                    done = False
                    If (Not conPointObj Is Nothing AndAlso conPointObj.ConPointID > 0) Then
                        If (item.UnitCode = "4HDP") Then 'Half Pallets
                            values += conPointObj.HalfPalletVol.ToString() + ";"
                            done = True
                        End If
                        If (item.UnitCode = "5TSP") Then 'Tall Pallets
                            values += conPointObj.TallPalletVol.ToString() + ";"
                            done = True
                        End If
                    End If
                    If (Not done) Then
                        For Each item1 As UnitSetting In unitValueListByConPoint
                            If (item.UnitSettingID = item1.UnitSettingID) Then
                                values += item1.CbmValue.ToString() + ";"
                                existed = True
                                Exit For
                            End If
                        Next
                        If (Not existed) Then
                            values += ";"
                        End If
                    End If

                    'If (item.ConPointID = RequestContext.ConPointIDForBODetailSS) Then
                    '    values += item.CbmValue.ToString() + ";"
                    'Else
                    '    values += ";"
                    'End If
                Next
                If (values.Length > 0) Then
                    values = values.Substring(0, values.Length - 1)
                End If
                hidUnitValueArray.Value = values
            Catch ex As Exception
            End Try

            ' refresh parent if requested
            If (RequestContext.RefreshParent) Then
                Page.RegisterStartupScript("windowClose", "<script language='javascript'>windowCloseAndRefresh();</script>")
                'by pass all the remain process 
                'render only closing script
                Exit Sub
            End If

            'If (RequestContext.TabID = 0) Then
            '    Me.pnlDOList.Visible = False
            '    Me.pnlGeneral.Visible = True
            'Else
            '    Me.pnlGeneral.Visible = False
            '    Me.pnlDOList.Visible = True
            'End If

            'BuildNavigator()

            Me.ddlOwner.DataSource = OfficeService.GetOffices(OfficeColumns.SortOrder, OrderDirection.ASC)
            Me.ddlOwner.DataTextField = OfficeColumns.OfficeName.ToString()
            Me.ddlOwner.DataValueField = OfficeColumns.OfficeID.ToString()
            Me.ddlOwner.DataBind()

            hidCurrentOwner.Value = ddlOwner.SelectedItem.Value

            ddlCat.DataSource = CatalogService.GetCatalogs(CatalogColumns.CatalogName, OrderDirection.ASC)
            ddlCat.DataTextField = CatalogColumns.CatalogName.ToString()
            ddlCat.DataValueField = CatalogColumns.CatalogID.ToString()
            ddlCat.DataBind()
            ddlCat.Items.Insert(0, New ListItem("[add new -->]", Nulls.NullInteger.ToString()))

            Me.ddlStockLocated.DataSource = SupplierService.GetSuppliers(SupplierColumns.SupplierCode, MyFramework.OrderDirection.ASC)
            Me.ddlStockLocated.DataTextField = SupplierColumns.SupplierCode.ToString()
            Me.ddlStockLocated.DataValueField = SupplierColumns.SupplierCode.ToString()
            Me.ddlStockLocated.DataBind()
            Me.ddlStockLocated.Items.Insert(0, New ListItem("", ""))

            ddlIDSSort.DataSource = IDSSortService.GetIDSSorts(IDSSortColumns.SortOrder, OrderDirection.ASC)
            ddlIDSSort.DataTextField = IDSSortColumns.Name.ToString()
            ddlIDSSort.DataValueField = IDSSortColumns.IDSSortID.ToString()
            ddlIDSSort.DataBind()
            ddlIDSSort.Items.Insert(0, New ListItem("", Nulls.NullInteger.ToString()))

            'ddlCurrency.DataSource = CurrencyService.GetCurrencies(CurrencyColumns.Code, OrderDirection.ASC)
            'ddlCurrency.DataTextField = CurrencyColumns.Code.ToString()
            'ddlCurrency.DataValueField = CurrencyColumns.CurrencyID.ToString()
            'ddlCurrency.DataBind()
            'ddlCurrency.Items.Insert(0, New ListItem("", Nulls.NullInteger.ToString()))

            ddlUnits.DataSource = UnitSettingService.GetUnitSettingsOnly()
            ddlUnits.DataTextField = UnitSettingColumns.Description.ToString()
            ddlUnits.DataValueField = UnitSettingColumns.UnitSettingID.ToString()
            ddlUnits.DataBind()
            ddlUnits.Items.Insert(0, New ListItem("-- select --", Nulls.NullInteger.ToString()))

            If (IsAddNew) Then
                ' initalize value
                Me.btnSubmit.Text = "Save & Next"
                Me.calOrderDate.SelectedValue = DateTime.Now
                Me.txtProductCode.Enabled = True

                ' set default to user's office
                ddlOwner.SelectedIndex = ddlOwner.Items.IndexOf(ddlOwner.Items.FindByValue(RequestContext.CurrentUser.ActiveOfficeID.ToString()))

                ' set default loc field to supplier number corresponding to the page that you are on
                Me.ddlStockLocated.SelectedIndex = ddlStockLocated.Items.IndexOf(ddlStockLocated.Items.FindByValue(RequestContext.SupplierCode))

                chkNotAvailInUSA.Checked = False

                ' set default LGD Catalog Pack Qty to 1
                txtPackQty.Text = "1"

                ' set default Total Quantity Completed to 0
                txtQtyCompleted.Text = "0"
            Else
                Me.btnSubmit.Text = "Save & Next"
                Me.txtProductCode.Enabled = False

                If BuildObject() Then
                    UpdateData(False)
                End If

                ' user can only change bo type from stock type to stock type
                ' if current bo type is "Stock xxx"
                If (Convert.ToInt32(ddlType.SelectedItem.Value) > 1) Then ' stock type
                    ' remove ordered type
                    Dim orderListItem As ListItem = ddlType.Items.FindByValue("1")
                    If Not (orderListItem Is Nothing) Then
                        Me.ddlType.Items.Remove(orderListItem)
                    End If
                End If
                'Me.ddlOwner.Enabled = False
            End If
            ' Hide picture at first if have
            spanShowPicture.Visible = False
            lnkViewProductPicture.Text = "View picture"
        End If
        lnkViewProductPicture.Attributes.Add("onclick", "javascript:NoneSubmit()")


    End Sub

    Private Sub NavigateNext()
        Dim id As String = RequestContext.BulkOrderID.ToString()
        Dim idx As Integer = RequestContext.SelectedIDs.IndexOf(id)

        ' the last item in RequestContext.SelectedIDs is a empty one
        ' by pass that item (Count - 2)
        If (idx < RequestContext.SelectedIDs.Count - 2) Then
            Response.Redirect(ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, Convert.ToInt32(RequestContext.SelectedIDs(idx + 1)), RequestContext.ChainOfID, False, True, 0)))
        Else
            Response.Redirect(ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, Convert.ToInt32(id), RequestContext.ChainOfID, True, True, 0)))
        End If
    End Sub

    Private Function SaveData() As Boolean
        If BuildObject() = False Then
            Return False
        End If
        UpdateData(True)

        If (boo.Type = EBOType.Ordered AndAlso boo.TotalQtyNotStarted < 0) Then
            Me.lblMessage.Text = "Total quantity not start must >= 0"
            Return False
        End If

        'If BulkOrderService.CheckUniqueBONo(boo.Owner, boo.BONo) > 0 Then
        '    lblMessage.Text = "This BO No has been used for this owner. Please enter another"
        '    Return False
        'End If

        Dim saveCompleted As Boolean = False

        Try
            If IsAddNew Then
                BulkOrderService.CreateBulkOrder(boo)
            Else
                BulkOrderService.UpdateBulkOrder(boo)
            End If
            pd.BulkOrderID = boo.BulkOrderID
            BulkOrderService.InsertOrUpdateProductDimensions(pd)
            UpdateProductDimensions(False, pd)
            saveCompleted = True

        Catch ex As Exception
            Me.lblMessage.Text = ex.Message
        End Try

        Return saveCompleted
    End Function

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If Page.IsValid Then
            'Logger.Debug("BODetail: BEGIN Submit click")
            Dim saveCompleted As Boolean = SaveData()

            If saveCompleted Then
                If IsAddNew Then
                    ' redirect to itself to add another and refresh the parent page
                    Response.Redirect(ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, 0, "", False, True, 0)))
                Else
                    NavigateNext()
                End If
            End If
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Page.IsValid Then
            If (SaveData()) Then
                Response.Redirect(ResolveUrl(UrlBuilder.GetBODetailUrl(RequestContext.SupplierCode, boo.BulkOrderID, RequestContext.ChainOfID, False, True, 0)))
            End If
        End If
    End Sub

    Private Sub btnFakeSubmit_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFakeSubmit.ServerClick
        ddlType.Items.Clear()
        ddlType.Items.Add(New ListItem("[--select]", "-1"))

        If ddlOwner.SelectedItem.Value = "9999" Then
            ddlType.Items.Add(New ListItem("Stock Clear", "2"))
            ddlType.Items.Add(New ListItem("Stock Fact", "3"))
        Else
            ddlType.Items.Add(New ListItem("Ordered", "1"))
            ddlType.Items.Add(New ListItem("Stock Clear", "2"))
            ddlType.Items.Add(New ListItem("Stock Fact", "3"))
        End If
    End Sub

    Protected Function GetPictureHTML() As String
        NoPicture = True
        If (ProductCode Is DBNull.Value OrElse ProductCode Is Nothing) AndAlso txtProductCode.Text.Trim.Length > 0 Then
            ProductCode = txtProductCode.Text.Trim
        End If
        If ProductCode Is DBNull.Value Then
            Return "&nbsp;"
        Else
            Dim filePath As String = String.Format("{0}.jpg", Path.Combine(Config.ProductImagePath, Convert.ToString(ProductCode)))
            If File.Exists(filePath) Then
                NoPicture = False
                Return String.Format("<img src='ViewPicture.aspx?procode={0}&size={1}' border=0 alt='{0}.jpg'>", ProductCode, Config.BOSalesReportImageSize)
            Else
                Return "&nbsp;"
            End If
        End If
    
    End Function

    Private Sub lnkViewProductPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkViewProductPicture.Click
        If (lnkViewProductPicture.Text = "View picture") Then
            spanShowPicture.Visible = True
            If (ProductCode Is DBNull.Value OrElse ProductCode Is Nothing) AndAlso txtProductCode.Text.Trim.Length > 0 Then
                ProductCode = txtProductCode.Text.Trim
            End If
            Dim filePath As String = String.Format("{0}.jpg", Path.Combine(Config.ProductImagePath, Convert.toString(ProductCode)))
            If File.Exists(filePath) Then
                lnkViewProductPicture.Text = "Hide picture"
            End If
        Else
            spanShowPicture.Visible = False
            lnkViewProductPicture.Text = "View picture"
        End If
    End Sub

    Property ProductCode() As Object
        Get
            Return viewState("ProductCode")
        End Get
        Set(ByVal Value As Object)
            viewState("ProductCode") = Value
        End Set
    End Property

    Property NoPicture() As Boolean
        Get
            Return CType(viewState("NoPicture"), Boolean)
        End Get
        Set(ByVal Value As Boolean)
            viewState("NoPicture") = Value
        End Set
    End Property

    Property BulkOrderID() As Object
        Get
            Return viewState("BulkOrderID")
        End Get
        Set(ByVal Value As Object)
            viewState("BulkOrderID") = Value
        End Set
    End Property
End Class
